<template>
	<div>
		<div class="wholePic">
	  	</div>
	    <div class="banner-text">
	    	<div class="logo"> 
	      		土壤监测与主动反馈系统
	    	</div>
	  	</div>

		<div id="logincontainer">
		    <div class="title">
		      登录
		    </div>  
		    <div class="login-form" id="login">
		      <div class="form-group">
		        <input type="text" class="form-control login-field" v-model="loginForm.user_name" placeholder="输入用户名" id="login-name">
		        <label class="login-field-icon fa fa-user" for="login-name"></label>
		      </div>
		  
		      <div class="form-group">
		        <input type="password" v-model="loginForm.password" class="form-control login-field" placeholder="输入密码" id="login-pass">
		        <label class="login-field-icon fa fa-lock" for="login-pass"></label>
		      </div>
		      <br/>
		      <button value="登录" class="btn btn-primary btn-large btn-block" @click="login()" type="submit">登录</button>
		    </div>
		  
		</div>
	</div>
</template>

<script>
// import './css/font-awesome.min.css'
import './css/initial.css'
import './css/login.css'
import {loginQuest} from '@/services/login.js'
import {setCookie,getCookie,delCookie} from '@/tools/cookie'

export default {
    name: 'login',
    data(){
        return{
        	loginForm:{
        		user_name:'',
        		password:''
        	}
        } 
    },
    methods:{
        login(){
        	if(this.loginForm.user_name==''){
        		this.$message({
		          message: '请输入用户名！',
		          type: 'warning'
		        });
        	}else if(this.loginForm.password==''){
        		this.$message({
		          message: '请输入密码!',
		          type: 'warning'
		        });
        	}else{
        		// loginQuest(this.loginForm).then(res=>{
        		// 	console.log(res.status)
        		// })
        		var vm=this
        		$.ajax({
		            url: "http://by.gole.site/api/login",
		            type: 'POST',
		            async:false,
		            data: JSON.stringify(this.loginForm),
		        }).done(function(res) {
		        	if(res.status==0){
		        		vm.$message({
				          message:res.msg,
				          type: 'warning'
				        });
		        	}else{
		        		setCookie('user_name',vm.loginForm.user_name,'h2')
		        		setCookie('token',res.token,'h2')
		        		setCookie('level',res.data.level,'h2')
		        		vm.$router.push('/system/equipmentMessage')
		        	}
		        }).fail(function(res) {
			        vm.$notify.error({
			          message: '登录失败！'
			        });
		        });
        	}
        }
    }
}
</script>

<style type="text/css">
	
</style>